/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        vector<vector<int>> ret;
        if(root == nullptr)
        {
            return ret;
        }
        queue<Node*> que;
        que.push(root);
        while(!que.empty())
        {
            int size = que.size();//获取这一层的数量
            vector<int> tmp;
            for(int i = 0;i<size;i++)
            {
                Node* node = que.front();
                que.pop();
                tmp.push_back(node->val);//将这一层的这个节点值放入到tmp中
                vector<Node*> child = node->children;//获取这个节点的儿子
                for(int i = 0;i<child.size();i++)
                {
                    if(child[i])//处理空节点
                        que.push(child[i]);//将这些儿子继续放入到队列中
                }
            }
            ret.push_back(tmp);
        }
        return ret;
    }
};